#ifndef CUSTOMMESSAGEBOX_H
#define CUSTOMMESSAGEBOX_H

#include <QObject>
#include <QWidget>

#include <QDialog>
#include <QPushButton>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QMap>

class CustomMessageBox : public QDialog
{
    Q_OBJECT

public:
    // 消息框类型
    enum Icon { NoIcon, Information, Warning, Critical, Question };

    // 按钮类型
    enum ButtonRole {
        Ok =  0x00000400,
        Yes = 0x00004000,
        No = 0x00010000,
        Cancel = 0x00400000,
        Close = 0x00200000,
        // 可以添加更多按钮类型
    };
    Q_DECLARE_FLAGS(ButtonRoles, ButtonRole)

    explicit CustomMessageBox(QWidget *parent = nullptr);
    ~CustomMessageBox();

    // 静态方法，方便调用
    static int information(QWidget *parent, const QString &title,
                          const QString &text, ButtonRoles buttons = Ok,
                          ButtonRoles defaultButton = Ok);
    static int warning(QWidget *parent, const QString &title,
                      const QString &text, ButtonRoles buttons = Ok,
                      ButtonRoles defaultButton = Ok);
    static int critical(QWidget *parent, const QString &title,
                       const QString &text, ButtonRoles buttons = Ok,
                       ButtonRoles defaultButton = Ok);
    static CustomMessageBox::ButtonRole question(QWidget *parent, const QString &title,
                       const QString &text, ButtonRoles buttons = ButtonRoles(Yes)|ButtonRoles(No),
                       ButtonRoles defaultButton = Yes);

    // 设置消息内容
    void setText(const QString &text);
    void setIcon(Icon icon);
    void setWindowTitle(const QString &title);

    // 添加按钮
    void addButton(const QString &text, ButtonRole role);

    // 获取用户点击的按钮
    ButtonRole clickedButton() const;

protected:
    void mousePressEvent(QMouseEvent *e) override;
    void mouseMoveEvent(QMouseEvent *e) override;
    void mouseReleaseEvent(QMouseEvent *e) override;

private slots:
    void onButtonClicked();

private:
    void initUI();
    QPixmap getIconPixmap(Icon icon) const;

    QLabel *m_iconLabel;
    QLabel *m_textLabel;
    QLabel *m_titleLabel;
    QHBoxLayout *m_buttonLayout;


    QMap<QPushButton*, ButtonRole> m_buttonRoles;

    ButtonRole m_clickedButton;
    QString  m_title;

    QPoint m_StartPos;
};

Q_DECLARE_OPERATORS_FOR_FLAGS(CustomMessageBox::ButtonRoles)

#endif // CUSTOMMESSAGEBOX_H
